/*
 * Copyright 2011 J. Auer, J. Andert, F.-J. Jendrusch, U. Celebi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.fuberlin.replication.library;

import java.io.Serializable;

/**
 * Auxiliary class for representing object-specific information (name, version, time changed).
 */
public class Metadata implements Serializable {
	private static final long serialVersionUID = 5426386753863850445L;

	/**
	 * The name of the associated object.
	 */
	private String name;

	/**
	 * The current version of the associated object.
	 */
	private Version version;

	/**
	 * Time at witch the associated object has been changed the last time.
	 */
	private long timestamp;

	/**
	 * Constructor for metadata object (if it already exists).
	 * 
	 * @param name Object's name
	 * @param version Object's current version
	 * @param timestamp Time of last change
	 */
	public Metadata(String name, Version version, long timestamp) {
		this.name = name;
		this.version = version;
		this.timestamp = timestamp;
	}

	/**
	 * Constructor for metadata object (if it is new).
	 * 
	 * @param name Object's name
	 * @param version Object's current version
	 */
	public Metadata(String name, Version version) {
		this.name = name;
		this.version = version;
		timestamp = System.currentTimeMillis();
	}

	/**
	 * Empty Constructor.
	 */
	public Metadata() {
		name = "";
	}

	@Override
	public String toString() {
		return "[" + name + ";" + version.toString() + "]";
	}

	/**
	 * Get the associated objects unique name.
	 * 
	 * @return Unique name of the associated object
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set the associated objects unique name.
	 * 
	 * @param name A unique name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Get the associated objects version.
	 * 
	 * @return Version of the associated object
	 */
	public Version getVersion() {
		return version;
	}

	/**
	 * Set the associated objects version.
	 * 
	 * @param version New Version object
	 */
	public void setVersion(Version version) {
		this.version = version;
		timestamp = System.currentTimeMillis();
	}

	/**
	 * Get a time stamp, representing the time the version of this object has changed last.
	 * 
	 * @return Time of last change
	 */
	public long getTimestamp() {
		return timestamp;
	}

	/**
	 * Set the time, when the version of this object has changed last.
	 * 
	 * @param timestamp Time of change
	 * @see #setVersion(Version version)
	 */
	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}
}